package org.RSG.Interface;

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

import org.RSG.Application.*;

public class ToolButton extends JComponent implements MouseListener
{
	private static final long serialVersionUID = 1L;
	private boolean isCurrentTool;
	public int toolID;
	private Image icon;
	public ToolButton(int toolID, Image icon)
	{
		this.toolID = toolID;
		this.icon = icon;
		if(Application.currentTool == this.toolID)
		{
			this.isCurrentTool = true;
		} else {
			this.isCurrentTool = false;
		}
		this.setPreferredSize(new Dimension(30, 30));
		this.addMouseListener(this);
	}
	
	public void currentTool(boolean yn)
	{
		this.isCurrentTool = yn;
		this.repaint();
	}
	
	public void paintComponent(Graphics g)
	{
		//Check still current tool
		if(Application.currentTool == this.toolID)
		{
			this.isCurrentTool = true;
		} else {
			this.isCurrentTool = false;
		}
		if(this.isCurrentTool)
		{
			g.setColor(new Color(255, 0, 153));
			g.fillRect(0, 0, this.getHeight() - 1, this.getWidth() - 1);
		}
		g.setColor(new Color(0, 0 , 0));
		g.drawRect(0, 0, this.getHeight() - 1, this.getWidth() - 1);
		//g.drawString("" + this.toolID, this.getWidth() - 19, this.getHeight() - 10);
		g.drawImage(this.icon, 7, 7, null);
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		Application.currentTool = this.toolID;
		this.currentTool(true);
		this.getParent().repaint();
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
}